package br.unisinos.projetotcc.pesquisa;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.MethodGen;
import org.apache.commons.beanutils.MethodUtils;

public class TesteBCEL {

	public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

		try {

//			ClassLoader classLoader = new ClassLoader();
//			URL resource = classLoader.getResource("C:\\Users\\MARVAN\\Desktop\\teste\\Teste");                                                                                 

			ClassParser classParser = new ClassParser("C:\\Users\\MARVAN\\Desktop\\teste\\Teste.class");
			
			JavaClass parse = classParser.parse();
			
			Method[] methods = parse.getMethods();
			
			
			
			MethodGen gen = new MethodGen(methods[0], "Teste", null);
			
			Object invokeStaticMethod = MethodUtils.invokeStaticMethod(parse.getClass(), "main", "");
			
			System.out.println(invokeStaticMethod);
			
			for (Method method : methods) {
				System.out.println(method.getName());
			}
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// ClassGen gen = new ClassGen(null, null,
		// "C:\\Users\\MARVAN\\Desktop\\teste\\Teste", 0, null);
		//
		// Method[] methods = gen.getMethods();
		//
		// for (Method method : methods) {
		// System.out.println(method.getName());
		// }

	}

}
